package com.umpay.junit.test.h5.gathering;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static org.springframework.test.util.AssertionErrors.fail;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.servlet.ModelAndView;

import com.umfwechat.h5.controller.TestController;
import com.umfwechat.h5.controller.gathering.GatheringController;
import com.umfwechat.h5.controller.sign.SignController;
import com.umfwechat.util.PropertyUtil;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath*:spring-context.xml"})
public class GatheringTestController {

    @Resource
    TestController ttestController;
    
    @Resource
    GatheringController gatheringController;

    private MockHttpServletRequest request;
    private MockHttpServletResponse response;

    static{
    	System.setProperty("resin.home","E:\\developSoft\\resin\\resin-4.0.48"); 
    	//String url = PropertyUtil.getStrValue("umfWeChatPlat_appConf.properties","junit.test.url", ""); 
    	//System.setProperty("resin.home", url);
    }


    @Before
    public void before()
    {
    	/**
    	 * 设置resin_home环境变量
    	 */
        request = new MockHttpServletRequest();
        response = new MockHttpServletResponse();
        request.setCharacterEncoding("UTF-8");
    }

    @Test
    public void test()
    {
        //request.setRequestURI("createProduct.htm");
        //request.setMethod(HttpMethod.POST.name());

        ModelAndView mv = null;
        try
        {
            mv = ttestController.test(request, response);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            fail("testToSearchPage failed!");
        }

        assertNotNull(mv);
        assertEquals(response.getStatus(), 200);
    }
    
	/**
	 * 获取调用扫一扫签名
	 * 
	 * @param request
	 * @param mav
	 * @return
	 */
	@Test
	public void getSignture() {

		try {
			HttpServletRequest request = new MockHttpServletRequest();
			String res = gatheringController.getSignture(request);
					System.out.println("res=" + res);
		} catch (Exception e) {
			e.printStackTrace();
			fail("testToSearchPage failed!");
		}

		assertEquals(response.getStatus(), 200);
	}

    /**
	 *收款页面初始化
	 */
    @Test
    public void getStoreGathering()
    {

        try
        {
        	HttpServletRequest request =new MockHttpServletRequest();
        	HttpServletResponse response = new MockHttpServletResponse();
            String res = gatheringController.getStoreGathering(request, response).toString();
           System.out.println("res="+res);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            fail("testToSearchPage failed!");
        }


        assertEquals(response.getStatus(), 200);
    }
    
    /**
	 * 收款
	 * 
	 * @param request
	 * @param mav
	 * @return
	 */
	@Test
	public void getddddd() {

		try {
			HttpServletRequest request = new MockHttpServletRequest();
			String merId="9996";
			String amount="1";
			String storeId="";
			String oriAmount="1";
			String authCode="287626426300582166";
			String storeShortName="";
		    String res=gatheringController.gathering(storeId,storeShortName, merId, amount, oriAmount, authCode,request);
					System.out.println("res=" + res);
		} catch (Exception e) {
			e.printStackTrace();
			fail("testToSearchPage failed!");
		}

		assertEquals(response.getStatus(), 200);
	}
    
    
}
